<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="hexinyang">
	<title>批量个人化不记名卡</title>
	<script language="javascript" src="../script/common.js" type="text/javascript"></script>	
<script type="text/javascript">    
	//页面控件初始化
	var cOrg = Common.cOrg();
	var qt,pqt;
	var count = 0;
	function load(){
		Eui.showNavigation();
		setPages(["listview","detview"]);
		searchForm.organization.value = cOrg.id;
		DWR.call("cardMgntService.findAnonCardType",function(result){
			Common.initDict(searchForm.cardType,result,"全部","0","1")
			createTable()
		})
	}
	

	//查询库存未个人化的不记名卡
	function createTable() {
		var columns = []
		columns[0] = {type:"checkbox"}
		columns[4] = {title:"操作",render:function(v,r){
			return "<a href=# onclick='personalize("+r[0]+","+r[2]+")'>个人化</a>"
		}}
		qt = new QueryTable("find_anon_cards", "searchForm", "datalist", columns, {
		});
		qt.showTable();
	}
	
	function personalize(ct,c){
		count = c;
		switchPage("detview");
		DWR.call("cardTypeService.loadCardType",ct,function(result){
			var cardType = result.cardType;
			cardType.baseCardTypeText = Common.getText("base_card_type",cardType.baseCardType);
			cardType.targetAreaName = result.targetAreaName;
			cardType.amount = c;
			cardType.cardStatusText = Common.getText("card_status",CardStatus.INITED)
			Common.showDetail("cardtypeview",cardType);
		});
		if (!pqt){
			createPersonalTable(ct);
		}else{
			setParams(ct)
			pqt.showTable();
		}
	}
	function createPersonalTable(ct) {
		var html = "<label>数量：</label> <input type=text id='personalize_amount' onblur=\"checkV(this,'number')\">";
		var columns = []
		columns[0] = {type:"checkbox"}
		pqt = new QueryTable("card_inventory", null, "personalizelist", columns, {
			buttons:[
				{name:"doPersonalize",value:"个人化",actions:doPersonalize}
			],
			doms:{
				type:"span",
				value : html
			}
		});
		setParams(ct)
		pqt.showTable();
	}
	function doPersonalize(){
		var ids = pqt.getBoxValue();
		if (!checkForm(listform)) return;
		var amount = $("personalize_amount").value;
		amount = amount?amount:0
		if (count < amount){showWarning("卡片数量不足！");return;}
		if (!ids)
			showWarning("请选择需要个人化的不记名卡。");
		else{
			if(showQuestion("是否个人化这些卡片？")){
				DWR.call("cardMgntService.personalizeAnons",ids,amount,function(){
					showInformation("个人化成功！");
					back();
				},{blockScreen:true});
			}
		}
	}
	
	function setParams(ct){
		pqt.paramFunc = function(){
			var params = {}
			params.showId = "true";
			params.locationId = cOrg.id;
			params.storeStatus = CardStoreStatus.STORE;
			params.cardStatus = CardStatus.INITED;
			params.cardTypeId = ct;
			return params;
		}
	}
	function back(){
		switchPage("listview");
		qt.showTable();
	}
</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview">
		<!--查询form-->
		<div class="searchForm">
			<form id="searchForm" name="searchForm">
				<input type="hidden" name="groupby" value="ct">
				<input type="hidden" name="organization">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0">
					<tr>
						<td>
							<label>卡片类型</label>
							<select name="cardType"><option></option></select>
						</td>
						<td><button type="button" onclick="qt.showTable()">查 询</button></td>
					</tr>
				</table>
			</form>
		</div>
	
		<div id="datalist"></div>
	</div>
	<div id="detview" style="display:none;">
		<div id="cardtypeview" class="form">
			<div class="formTitle">卡片类型信息</div>
			<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="viewTable col3">
				<tr>
					<td><label>名&nbsp;&nbsp;&nbsp;&nbsp;称</label> <span id="name"></span></td>
					<td><label>基本类型</label> <span id="baseCardTypeText"></span></td>
					<td><label>初始金额</label> <span id="initBalance"></span></td>
				</tr>
				<tr>
					<td><label>使用区域</label> <span id="targetAreaName"></span></td>
					<td><label>商品限制</label> <span id="restrictCommodities"></span></td>
					<td><label>客户级别</label> <span id="userLevelText"></span></td>
				</tr>
				<tr>
					<td><label>卡片状态</label> <span id="cardStatusText"></span></td>
					<td><label>有效时间</label> <span id="validityDay"></span></td>
					<td><label>可延长时间</label> <span id="daysPerExtention"></span></td>
				</tr>
			</table>
		</div>
		<form id="listform" name="listform" >
		<div id="personalizelist">
		</div>
		</form>
		<div>
			<button onclick="back()">返 回</button>
		</div>
	</div>
</body>
</html>